package com.example.diagnose.Config;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Repository;

@Builder
@NoArgsConstructor
@Getter
@Data
@Repository

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class CommonResponse<T> {
    private int status;
    private String message;
    private T data;
    private String link;


    //不同的构造方法
    public CommonResponse(int status, String message){
        this.status = status;
        this.message = message;
    }

    private CommonResponse(int status, String message, T data){
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public CommonResponse(int status, String message, String link){
        this.status = status;
        this.message = message;
        this.link = link;
    }

    private CommonResponse(int status, String message, T data, String link){
        this.status = status;
        this.message = message;
        this.data = data;
        this.link = link;
    }

    public static  <T>CommonResponse<T> BackForSuccess(String message){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), message);
    }

    public static  <T>CommonResponse<T> BackForSuccess(String message,T data){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), message, data);
    }

    public static  <T>CommonResponse<T> BackForSuccess(T data){
        // System.out.println(data);
        return new CommonResponse<T>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDesc(),data);
    }

    public static  <T>CommonResponse<T> BackForSuccess(String message, String link){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), message, link);
    }

    public static  <T>CommonResponse<T> BackForSuccess(String message,T data,String link){
        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), message, data, link);
    }

    public static  <T>CommonResponse<T> BackForError(){
        return new CommonResponse<>(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDesc());
    }

    public static  <T>CommonResponse<T> BackForError(String message){
        return new CommonResponse<>(ResponseCode.ERROR.getCode(), message);
    }

    public static  <T>CommonResponse<T> BackForError(int code,String message){
        return new CommonResponse<>(code,message);
    }

}
